<?php

class SitemapController extends Controller {
	
	protected $urls = array();
	
	public $models = array("News", "Gallery");
	
	public function index() {
		$urls = array();
		
		// menu items
		$menu = $this->template_parser->_tpl_vars["menu"];
		foreach ($menu as $item) {
			$this->_add_url($item["link"], date("Y-m-d"), "monthly", 0.8);
		}
		
		// news
		$news = $this->News->find(array("id", "title"), false, false);
		foreach ($news as $n) {
			$this->_add_url("/news/show/{$n["id"]}/".urlencode($n["title"]), date("Y-m-d"),"daily",1);
		}
		
		$this->assign("urls", $this->urls);
		header("Content-Type: application/xml; encoding=UTF-8");
		echo $this->parse("sitemap.xml");
	}
	
	private function _add_url($location, $modified, $change_freq, $priority=0.5) {
		$this->urls[] = array(
			"location" => "http://".$_SERVER["SERVER_NAME"].$location,
			"modified" => $modified,
			"change_freq" => $change_freq,
			"priority" => $priority
		);
	}
	
}

?>